package org.apache.flink.runtime.webmonitor;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.api.common.ConsumingStatus;
import org.apache.flink.api.common.ResourceStatus;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.runtime.allocation.ResourceAllocation;
import org.apache.flink.runtime.allocation.ResourceAllocationStatistics;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.messages.Acknowledge;
import org.apache.flink.runtime.messages.webmonitor.ClusterOverview;
import org.apache.flink.runtime.metrics.dump.MetricQueryService;
import org.apache.flink.runtime.rest.messages.ThreadDumpInfo;
import org.apache.flink.runtime.rpc.RpcGateway;
import org.apache.flink.runtime.rpc.RpcTimeout;

/**
 * @类名: RestfulGateway
 * @说明: restful网关
 *        接入到rest服务，资源状态；消费状态；metrics
 *
 * @author   leehom
 * @Date	 2024年1月4日 下午2:10:36
 * 修改记录：
 *
 * @see 	 
 */
/**
 * Gateway for restful endpoints.
 *
 * <p>Gateways which implement this method run a REST endpoint which is reachable under the returned
 * address.
 */
public interface RestfulGateway extends RpcGateway {

    /**
     * Cancel consuming
     *
     * @param timeout of the operation
     * @return A future acknowledge if the cancellation succeeded
     */
    CompletableFuture<Acknowledge> cancel(ConsumerID jobId, @RpcTimeout Time timeout);

    /**
     * @说明：请求资源分配状态
     *
     * @author leehom
     * @param timeout
     * @return
     * 
     */
    CompletableFuture<ResourceAllocation> requestResourceAllocation(@RpcTimeout Time timeout);

    /**
     * @说明：请求资源分配统计
     *
     * @author leehom
     * @param timeout
     * @return
     * 
     */
    CompletableFuture<ResourceAllocationStatistics> requestResourceAllocationStatistics(@RpcTimeout Time timeout);

    /**
     * Requests the addresses of the {@link MetricQueryService} to query.
     *
     * @param timeout for the asynchronous operation
     * @return Future containing the collection of metric query service addresses to query
     */
    CompletableFuture<Collection<String>> requestMetricQueryServiceAddresses(
            @RpcTimeout Time timeout);

    /**
     * Requests the addresses for the TaskManagers' {@link MetricQueryService} to query.
     *
     * @param timeout for the asynchronous operation
     * @return Future containing the collection of instance ids and the corresponding metric query
     *     service address
     */
    CompletableFuture<Collection<Tuple2<ResourceID, String>>>
            requestTaskManagerMetricQueryServiceAddresses(@RpcTimeout Time timeout);

    /**
     * Requests the thread dump from the ResourceConsumer.
     *
     * @param timeout timeout of the asynchronous operation
     * @return Future containing the thread dump information
     */
    CompletableFuture<ThreadDumpInfo> requestThreadDump(@RpcTimeout Time timeout);

    /**
     * @说明：请求资源状态
     *
     * @author leehom
     * @param timeout
     * @return
     * 
     * @see
     */
    CompletableFuture<ResourceStatus> requestResourceStatus(@RpcTimeout Time timeout);
    
    /**
     * @说明：请求资源消费结果
     *
     * @author leehom
     * @param timeout
     * @return
     * 
     * @see
     */
    CompletableFuture<ConsumingStatus> requestConsumingStatus(@RpcTimeout Time timeout);
    
    /**
     * Requests the cluster status overview.
     *
     * @param timeout for the asynchronous operation
     * @return Future containing the status overview
     */
    CompletableFuture<ClusterOverview> requestClusterOverview(@RpcTimeout Time timeout);
    
    default CompletableFuture<Acknowledge> shutDownCluster() {
        throw new UnsupportedOperationException();
    }

}
